package com.kehutong.common.filter;

import java.util.List;

import org.coraframework.orm.jdbc.execute.DataFilter;
import org.coraframework.orm.jdbc.execute.ICondition;
import org.coraframework.orm.util.FilterBean;
import org.coraframework.util.Objects;

import com.kehutong.common.entity.Root;

public class OfficeChirldFilter implements DataFilter {

	@Override
	public String name() {
		return "2";
	}

	@Override
	public void filter(FilterBean bean, ICondition<?> condition) {
		List<String> officeList = bean.getOfficeList();
		
		if (filterAble(officeList)) {
			condition.markBegin();
			for (String office : officeList) {
				condition.like(bean.getFullFieldName(), office).or();
			}
			condition.markEnd();
		}
	}
	
	@Override
	public int level() {
		return 2;
	}
	
	private boolean filterAble(List<String> officeList) {
		if (Objects.isEmpty(officeList)) {
			return false;
		}
		
		for (String office : officeList) {
			if (Root.isRoot(office)) {
				return false;
			}
		}
		
		return true;
	}



}
